package com.example.trb.controller.performance;

import com.example.trb.dto.ObjectDTO;
import com.example.trb.entity.PerformancePatent;
import com.example.trb.entity.group.Insert;
import com.example.trb.entity.group.Update;
import com.example.trb.service.performance.PerformancePatentService;
import com.example.trb.util.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class PerformancePatentController {
    @Autowired
    PerformancePatentService ppService;
    @Value("${session_user}")
    String userKey;

    @PutMapping("/performancepatent")
    public CommonResult putPerformancePatent(@RequestBody @Validated(Update.class) PerformancePatent data) {
        ppService.update(data);
        return CommonResult.success(null);
    }

    @DeleteMapping("/performancepatent")
    public CommonResult deletePerformancePatent(@RequestBody PerformancePatent data) {
        ppService.removeById(data.getId());
        return CommonResult.success(null);
    }


    @PostMapping("/performancepatent/status")
    public CommonResult status(@RequestParam("id") Integer id,@RequestParam("status") String status)  {
        ppService.updateStatusById(id,status);
        return CommonResult.success(null);
    }

    @GetMapping("/performancepatent")
    public CommonResult getPerformancePatent(@RequestParam("id") Integer id) {
        ObjectDTO dto = ppService.getById(id);
        return CommonResult.success(dto.getData());
    }

    @PostMapping("/performancepatent")
    public CommonResult addPerformancePatent(@RequestBody @Validated(Insert.class) PerformancePatent data) {
        ObjectDTO dto = ppService.save(data);
        return CommonResult.success(dto.getData());
    }
}
